Skip to content

Fix paginated EPUB resources opening on their first page instead of the initial location - #947

Open
Jackolix wants to merge 1 commit into
readium:developfrom
Jackolix:fix/snap-offset-unmeasured-viewport
Open

Jackolix wants to merge 1 commit into
readium:developfrom
Jackolix:fix/snap-offset-unmeasured-viewport

Conversation

@Jackolix

Copy link
Copy Markdown

Summary

Now and then a reflowable EPUB in paginated mode opens on the first page of the right resource instead of at the initialLocation, and the navigator reports progression: 0. spreadDidLoad() scrolls after a fixed 0.2 s, but snapOffset() divides by viewportWidth, which stays 0 until the ResizeObserver frame has run. When that frame is late, the offset is NaN and the page doesn't move.

Fixes #946

Change

  • snapOffset() falls back to window.innerWidth while viewportWidth is still 0. That is the value onViewportWidthChanged() stores anyway. scrollToPosition(), scrollToId() and scrollToLocator() all snap through it.
  • Bundles regenerated with make scripts.
  • CHANGELOG entry under Unreleased › Fixed › Navigator.

Review notes

  • Only the paginated snap is affected. Scroll mode doesn't snap.
  • Once the observer has run, nothing changes: viewportWidth is non-zero and used as before.
  • The fixed 0.2 s delay in spreadDidLoad() (and its TODO) is left as is. Waiting for the first ResizeObserver pass would be the more thorough fix. I kept this PR minimal, but I'm happy to look into that if you prefer.

Verification

  • make scripts passes on develop (format, lint, typecheck, 139 Jest tests, bundle) with Node 24. Only readium-reflowable.js and readium-fixed.js changed.
  • Our app is on 3.10.0, where snapOffset(), scrollToPosition() and spreadDidLoad() are the same as on develop. I tested the same change there, with the bundle rebuilt, on an iOS 27.2 simulator (iPhone 17 Pro). Each run was a fresh install, opening a locator at progression: 0.504 in an 8-page resource, with the 0.2 s changed to 0 to force the race:
    • Without this change: 6/6 opens stayed on the first page.
    • With this change: 6/6 opened on page 5.
    • With the usual 0.2 s: opening and three page turns behave as before.

Not covered

  • No unit test: utils.js is plain JavaScript with side effects at load, and the Jest setup only transforms .ts. Testing snapOffset() would need it moved to a TypeScript module, which seemed out of scope.
  • Not tested on a physical device, in RTL, or in two-column spreads. The fallback is the same window.innerWidth the observer would have stored, so those paths should behave as before once measured.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Paginated EPUB sometimes opens on the resource's first page instead of the initial location

1 participant